package com.gzdh.tang.modu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gzdh.tang.modu.entity.Addr;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TangAddrMapper extends BaseMapper<Addr> {


    @Select("WITH tree AS ( " +
            "SELECT addr_no,addr_name,addr_pos,parent_id,sub_mch_id,lev = 0 FROM addr  WHERE addr_no = #{addrNo} " +
            "              UNION ALL " +
            "                  SELECT b.addr_no,b.addr_name,b.addr_pos,b.parent_id,b.sub_mch_id,lev = tree.lev + 1 " +
            "                    FROM tree INNER JOIN addr b ON tree.addr_no = b.parent_id " +
            "           ) " +
            "            SELECT * FROM  tree ORDER BY tree.lev " +
            "         OPTION (MAXRECURSION 0); -- 该处设置最大递归次数，默认是100，设置为0则递归次数不限")
    List<Addr> getAddrTree(@Param("addrNo")int addrNo);

}
